export type OpenPlayletPage = {
  /** 剧目ID */
  dramaId: number;
  /** 第三方剧目ID */
  thirdDramaId?: string;
  /** 第三方剧集ID */
  thirdEpisodeId?: string;
  /**剧集ID */
  episodeId: number;
  /** 第几集 */
  episodeSeq: number;
  /** 微信短剧提审方appID */
  srcAppid: string;
};

/**
 * 得到跳转的url
 */
export function getOpenPlayletPageUrl(param: OpenPlayletPage): string {
  const { dramaId, thirdDramaId, thirdEpisodeId, episodeId, episodeSeq } = param;
  const srcAppid = param.srcAppid;

  let url = ``;

  // #ifndef MP-TOUTIAO || MP-WEIXIN || MP-KUAISHOU
  url = `/pages/drama/playlet-public/playlet-public`;
  url += `?dramaId=${dramaId}&episodeId=${episodeId}`;
  // #endif

  // #ifdef APP-PLUS
  url = `/pages/drama/playlet-app/playlet-app`;
  url += `?dramaId=${dramaId}&episodeId=${episodeId}`;
  // #endif

  // #ifdef MP-KUAISHOU
  url = `/pages/drama/playlet-ks/playlet-ks`;
  url += `?ksPlayletId=${thirdDramaId}&ksEpisodeId=${thirdEpisodeId}&ksSeq=${episodeSeq}`;
  // #endif

  // #ifdef MP-TOUTIAO
  url = `/pages/drama/playlet-tt/playlet-tt`;
  url += `?tt_album_id=${thirdDramaId}&tt_episode_id=${thirdEpisodeId}`;
  // #endif

  // #ifdef MP-WEIXIN
  url = `plugin-private://wx94a6522b1d640c3b/pages/playlet/playlet`;
  url += `?dramaId=${thirdDramaId}&srcAppid=${srcAppid}&serialNo=${episodeSeq}`;
  // #endif

  return url;
}

/**
 * 跳转到短剧播放页面
 */
export function openPlayletPage(param: OpenPlayletPage) {
  uni.navigateTo({ url: getOpenPlayletPageUrl(param) });
}
